from crm.base.crm_browser import BrowserOperation
from crm.base.crm_browserex import BrowserOperationEx
from crm.base.crm_use_browser import UseBrowser
from crm.util.exl_operation import ExlOpera
from crm.util.yaml_operation import YamlOperation

class LoginPage:

    def __init__(self):
        self.ub = UseBrowser()  # 实例化浏览器
        self.bo = BrowserOperation(self.ub.driver)
        self.boex = BrowserOperationEx(self.ub.driver)
        self.yo=YamlOperation()
        self.exl=ExlOpera()
        self.exl.get_sheet('登录用例参数')

    def login(self,username,password):
        self.bo.open_url(self.exl.get_cell(1,1))
        self.bo.input_text('name', self.yo.get_locator('LoginPage','username'), username)
        self.bo.input_text('name', self.yo.get_locator('LoginPage','password'), password)
        self.bo.click('id', self.yo.get_locator('LoginPage','submit'))

    #获取登录成功的信息
    def login_suc_info(self):
        self.boex.change_frame(self.yo.get_locator('Brow','top_frame'))
        suc_info=self.bo.get_text('xpath',self.yo.get_locator('LoginPage','suc_info_xpath'))  #获取文本
        return suc_info

    # 获取登录失败的弹窗文本
    def login_error_info(self):
        return self.bo.alert_opertaion()